package com.ruoyi.ly.controller;


import com.ruoyi.ly.domain.dto.*;

import com.ruoyi.ly.domain.vo.SpaceBanUpdateVO;
import com.ruoyi.ly.service.SpaceBanService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@CrossOrigin
@RestController
@RequestMapping("/spaceBan")
@Slf4j
@Api(tags = "楼栋管理接口")
public class SpaceBanController {
    @Autowired
    private SpaceBanService spaceBanService;

    //分页查询
    @ApiOperation("分页查询楼栋")
    @GetMapping("/page")
    public Result<PageResult> page(PageSpaceBanDTO pageSpaceBanDTO) {
        log.info("分页查询：{}", pageSpaceBanDTO);
        PageResult pageResult = spaceBanService.pageQuery(pageSpaceBanDTO);
        return Result.success(pageResult);
    }

    //添加楼栋
    @ApiOperation("添加楼栋")
    @PostMapping("/add")
    private Result insert(@RequestBody SpaceBanAddDTO spaceBanAddDTO) {
        log.info("添加楼栋：{}", spaceBanAddDTO);
        spaceBanService.insert(spaceBanAddDTO);
        return Result.success();
    }

    //删除楼栋
    @ApiOperation("删除楼栋")
    @DeleteMapping("/delete/{banId}")
    public Result delete(@PathVariable("banId")Integer banId) {
        log.info("删除楼栋：{}", banId);
        spaceBanService.delete(banId);
        return Result.success();
    }


    //楼栋信息导出
    @ApiOperation("楼栋信息导出")
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        spaceBanService.exportData(response);
    }

    //修改楼栋
    @ApiOperation("修改楼栋")
    @PutMapping("/update")
    public Result update(@RequestBody SpaceBanUpdateDTO spaceBanUpdateDTO) {
        log.info("修改楼栋：{}", spaceBanUpdateDTO);
        spaceBanService.update(spaceBanUpdateDTO);
        return Result.success();
    }

    //根据楼栋ban_id查询楼栋
    @ApiOperation("根据楼栋ban_id查询楼栋")
    @GetMapping("/selectById")
    public  Result<SpaceBanUpdateVO> selectById(Long banId) {
        log.info("根据楼栋ban_id查询楼栋：{}",banId);
        SpaceBanUpdateVO spaceBanUpdateVO  = spaceBanService.selectById(banId);
        return Result.success(spaceBanUpdateVO);
    }

}
